package com.wman.sheep.widget.typeface;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.TextView;

import com.wman.sheep.R;


@SuppressLint("AppCompatCustomView")
public class TTextView extends TextView {

    public TTextView(Context context) {
        this(context, null);
    }

    public TTextView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public TTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

        init(context, attrs, defStyle);
    }

    private void init(Context context, AttributeSet attrs, int defStyle) {
        if (attrs != null) {
            TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ui_typeface);
            String typeface = a.getString(R.styleable.ui_typeface_ui_typeface);
            if ("2".equals(typeface)) {
                super.setTypeface(UITypeface.getTypeFace(context, UITypeface.TypeFace.SemiBold));
            } else if ("1".equals(typeface)) {
                super.setTypeface(UITypeface.getTypeFace(context, UITypeface.TypeFace.Xiyuan));
            } else {
                super.setTypeface(UITypeface.DEFAULT);
            }
            a.recycle();
        } else {
            super.setTypeface(UITypeface.DEFAULT);
        }
    }
}
